package com.hongxin.nw.netty.model.packing.info;

import com.hongxin.nw.netty.utils.FieldPack;
import com.hongxin.nw.netty.values.TypeIdentif;
import lombok.extern.slf4j.Slf4j;

/**
 * @remark A.4充电记录确认数据
 * @author: GuoXiaolin
 * @date 2019/5/28 10:05
 * @Version 1.0
 * @Descibe
 */
@Slf4j
public class Csdna1_3  implements IPacking {

    private String co;//1	充电设备编号	压缩BCD码	8Byte	充电设备编号
    private String chargeIdentify;//2	充电接口标识	BIN码	1Byte	充电设备为一桩多充时用来标记接口号，一桩一充时此项为0。多个接口时顺序对每个接口进行编号
    private String successIdentify;//3	成功标志	BIN码	1Btype	最高位：0：成功；1：失败 低7位：失败原因 1:SM4密钥错误 127:其它原因

    public Csdna1_3 setCo(String co) {
        this.co = FieldPack.caseToBCD(co, TypeIdentif.BYTE_CO.getByteLength());
        return this;
    }

    public Csdna1_3 setChargeIdentify(String chargeIdentify) {
        this.chargeIdentify = FieldPack.caseToBin(chargeIdentify, TypeIdentif.BYTE_CHARGE_INTERFACE_IDENTIFY.getByteLength());
        return this;
    }

    public Csdna1_3 setSuccessIdentify(int successIdentify) {
        this.successIdentify = FieldPack.caseToSuccess(successIdentify, TypeIdentif.BYTE_SUCCESS_IDENTIFY.getByteLength());
        return this;
    }

    @Override
    public String packing() {
        return this.co +
                this.chargeIdentify +
                this.successIdentify;
    }

    @Override
    public String toString() {
        return "Csdna1_3{" +
                "co='" + co + '\'' +
                ", chargeIdentify='" + chargeIdentify + '\'' +
                ", successIdentify='" + successIdentify + '\'' +
                '}';
    }
}
